

import Vue from 'vue'
import axios from "axios";
function init() {
    console.log("开发环境",process.env.PATH_TYPE);
    let env = process.env.PATH_TYPE || "test";
    let mainsite = "http://localhost:3830";
    let user = "http://193.112.113.88:3819";
    let api = {}
    // env = 'dev';
    if (env) {
        switch (env) {
            case 'online':
                mainsite = 'https://api.soew.cn';
                user = 'https://user.soew.cn';
                break;
            case 'test':
                mainsite = 'http://193.112.113.88:3830';
                user = 'http://193.112.113.88:3819';
                break;
            case 'local':
                mainsite = 'http://localhost:3830';
                user = 'http://193.112.113.88:3819';
                break;
            default:
        }
    }
    // 搜索产品
    api["product_search"] = mainsite + '/product/search';
    api["vip_user_product"] = mainsite + '/product/nolimit/vip_user_product';
    return api;
}
Vue.prototype.$api = init()

function getFunc(url,params) {
    axios.defaults.headers.common['token'] = "test";
    return new Promise((reslove,reject)=>{
        axios.get(url,params||{}).then(res=>{
            reslove(res.data)
        }).catch(err=>{
            reject(res.data)
        })
    })
    
}
Vue.prototype.$get = getFunc
function postFunc(url,params) {
    axios.defaults.headers.common['token'] = "test";
    return new Promise((reslove,reject)=>{
        axios.get(url,params||{}).then(res=>{
            reslove(res.data)
        }).catch(err=>{
            reject(res.data)
        })
    })
    
}
Vue.prototype.$post = postFunc